package action.path;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import component.ShowDailogComponent;
import constants.Constants;
import utils.GameUtils;

/**
 * @Auther syc.
 * @Date 2016/11/11 14:14.
 */
public class ClientPathConfigAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        Application application = ApplicationManager.getApplication();
        ShowDailogComponent component = application.getComponent(ShowDailogComponent.class);

        //get the current project path
        String oldPath = GameUtils.getPropertyValue(anActionEvent, Constants.CLIENT_PATH_PRO_NAME);

        Project project = anActionEvent.getProject();
        if(null == oldPath) oldPath = "";
        String path = component.showInputDialog(project, "\n当前客户端目录为：" + oldPath +
                "\n请输入客户端目录：\n示例(..\\resource\\trunk)", oldPath, "Client Path");

        if(null != path) GameUtils.setGameProperties(anActionEvent, Constants.CLIENT_PATH_PRO_NAME, path, "modify the client path");
    }
}
